package com.invest;


import org.junit.jupiter.api.Test;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.HashSet;
import java.util.Set;


public class SeleniumExample {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe"); // 设置ChromeDriver的路径
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.jisilu.cn/web/data/cb/list"); // 替换为你的目标网址




        // 假设 cookies 是从浏览器或某个地方获取的
        Set<Cookie> cookies = new HashSet<>();

        // 逐个设置 cookie，注意以下 cookie 值是从你提供的字符串中提取的
        cookies.add(new Cookie("kbz_newcookie", "1"));
        cookies.add(new Cookie("kbzw__Session", "a829joql7sc5d7kf1lvo450474"));
        cookies.add(new Cookie("Hm_lvt_164fe01b1433a19b507595a43bf58262", "1735979592,1736007563,1736171693,1736431672"));
        cookies.add(new Cookie("HMACCOUNT", "122554C04A21E3AA"));
        cookies.add(new Cookie("Hm_lpvt_164fe01b1433a19b507595a43bf58262", "1736442356"));
        cookies.add(new Cookie("kbzw__user_login", "7Obd08_P1ebax9aXWx8WSSYrWQDyVfAfXgoOmqek0tfU6u7i6sXOvp_e25-vnKybppassNitxaCTqrHZoqnSrMWpxqzZ1a-S1IKvpurS3crUjauZqaumroKrjrXN08akna6VrJWrqaatmJGcoc62x9aXxNHwyuPj1KeWnpGUoczS59Dm2emBxcuTqZGeka-ZzNLnoqudltmtq5yYouDR4N7Mztu34NallqquoauXkIm_wcm2xZiXzt_M3Je63cTb0J2ZuNHr2-THpZKqqKGoj6CPpJnIyt_N6cullqquoauXkKbY4KSarJ2lkqSRpac"));

        // 将 cookies 添加到浏览器
        for (Cookie cookie : cookies) {
            driver.manage().addCookie(cookie);
        }


        // 刷新页面以确保 cookies 生效
        driver.navigate().refresh();

        // 设置 cookies
        for (Cookie cookie : cookies) {
            driver.manage().addCookie(cookie);
        }

        // 等待页面加载，这里简单地等待5秒，实际项目中可能需要更智能的等待条件
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        String pageSource = driver.getPageSource(); // 获取页面的HTML内容
        System.out.println(pageSource);

        driver.quit(); // 关闭浏览器
    }
}
